//
//  Fifth_LessonViewController.m
//  Fifth Lesson
//
//  Created by Diney Bomfim on 6/5/11.
//  Copyright 2011 DB-Interactive. All rights reserved.
//

#import "Fifth_LessonViewController.h"

@implementation Fifth_LessonViewController

- (void)dealloc
{
	[mesh release];
	[camera release];
	
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

//*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
	
	// Enable multiple touches on this view.
	self.view.multipleTouchEnabled = YES;
	
	NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
							  [NSNumber numberWithBool:YES], kNGLMeshAutoCentralize,
							  [NSNumber numberWithBool:YES], kNGLMeshAutoNormalize,
							  nil];
	
	// NinevehGL Meshes
	mesh = [[NGLMesh alloc] initWithDAEFile:@"medieval scene.dae" setProperties:settings];
	camera = [[NGLCamera alloc] initWithMeshes:mesh, nil];
}
//*/

- (void) drawView
{
	[camera moveRelativeTo:NGLMoveForward distance:[motionController getVertical:([motionController getDistance] / 20)]];
	camera.rotateX -= [viewController getCamera:[viewController getDistance]].y * 5;
	camera.rotateY -= [viewController getCamera:[viewController getDistance]].x * 5;
	
	[camera drawCamera];
	
	distance = 0.0;
	position.x = 0.0;
	position.y =0.0;
}

- (IBAction)resetView:(id)sender {
    [camera release];
    camera = [[NGLCamera alloc] initWithMeshes:mesh, nil];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

@end
